package cn.gson.crm.controller.position;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.PositionDao;
import cn.gson.crm.model.entity.Position;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class PositionDeleteServlet
 */
@WebServlet("/position/delete")
public class PositionDeleteServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private PositionDao postDao = new PositionDao();
	private String postId = null;
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String[] ids = request.getParameterValues("id");
		String postStatus = request.getParameter("postStatus");
		Integer count = 0;
		
			for (String id: ids) {
				Position post = new Position();
				post.setPostId(Integer.parseInt((String)id));
				post.setPostStatus(Integer.parseInt((String)postStatus));
				if(postDao.deletePost(post)){
					count++;
				}
			}	
			if(count == ids.length){
				redirect("position?postStatus="+postStatus);
				return;
			}
			
			
	}
}
